<link rel="stylesheet" type="text/css" href="/public/static/css/index.css" />
<script src="/public/static/js/jquery.min.js"></script>
<script src="/public/static/plugin/layer/layer.js"></script>
<style>
.contain{
	margin-top: 15px;
	padding-left: 10px;
	font-size:14px;
	margin-right: 10px;
	font-family: 微软雅黑, "Source Sans Pro", sans-serif;
	width: 700px;
}
.zs{
	color: #72afd2;
	line-height: 20px;
	
}
.title{font-size: 14px;margin-top: 20px;margin-bottom: 37px;}
.version{margin-bottom: 10px;}

.btn{
		height: 28px;
        line-height: 28px;
        margin: 0px 25px 0;
        padding: 5px 15px;
        border: 1px solid #dedede;
        color: #FFFFFF;
        border-radius: 2px;
        font-weight: 400;
        cursor: pointer;
        text-decoration: none;
        background: #5cb85c;
        border-color: ##5cb85c;
	}   

</style>

<div class="contain">
	<div class="zs">
		<div style="color: #000000;">操作说明：</div>
		<div>
			后端版本更新需要<font color="red"> 停服、分发更新包、检查更新包、更新、检查版本号、开服</font>这6个操作按从头到尾的顺序进行操作；<br />
		</div>
		
	</div>
	<div class="title">		
		<input type="hidden" name="ids" id="ids" value="<{$ids}>" />
		<{$info}>
	</div>
	<div class="version">
		<a href="javascript:;" id="version_stop_server" name="version_stop_server" class="btn" style="margin-right: 5px;" data-url="?r=serverOps/version_stop_server">停服</a>
		<a href="javascript:;" id="version_hand_out" name="version_hand_out" class="btn" style="margin-right: 5px;" data-url="?r=serverOps/version_hand_out">分发更新包</a>
		<a href="javascript:;" id="version_check" name="version_check" class="btn" style="margin-right: 5px;" data-url="?r=serverOps/version_check">检查更新包</a>
		<a href="javascript:;" id="version_update_oper" name="version_update_oper" class="btn" style="margin-right: 5px;" data-url="?r=serverOps/version_update_oper">更新</a>
		<a href="javascript:;" id="version_test" name="version_test" class="btn" style="margin-right: 5px;" data-url="?r=serverOps/version_test">检查版本号</a>
		<a href="javascript:;" id="version_open_server" name="version_open_server" class="btn" style="margin-right: 5px;" data-url="?r=serverOps/version_open_server">开服</a>
	</div>
	
	<div style="color: red;margin-left: 30px;margin-bottom: 20px;" id="update_version_info">
		
	</div>
	
	<div class="version" style="margin-bottom: 50px;">
		<a href="javascript:;" id="version_return" name="version_return" class="btn" style="margin-right: 5px;background-color: #72afd2;" data-url="?r=serverOps/version_return">设置操作回到上一步</a>
	</div>
	 
		
</div>



<script>
	//var cz_status = parent.document.getElementById("cz_status").value;
	//parent.document.getElementById("cz_status").value = 6;
	//停服
	$('a[name="version_stop_server"]').click(function(){
		var cz_status = parent.document.getElementById("cz_status").value;
		if(cz_status == 6){
			layer.alert('后端版本更新操作已经全部完成，请点击完成！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
		}
		
		var ids = $('input[name="ids"]').val();
		if(ids == ""){
            layer.alert('请先选择要停服的数据！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
        }
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
        var data_url = $('a[name="version_stop_server"]').attr('data-url');
        var g = $("input[name='g']").val();
        var url = data_url+'&g='+g;
        $.ajax({
        	type : 'POST',
    		url : url,
			data : {'ids':ids},
			dataType :'JSON',
			success : function(res){
				layer.close(uploading);
				if(res.status == 1){
					parent.document.getElementById("cz_status").value = 1;
					$("#update_version_info").text('停服操作完成!')
			        layer.alert(res.msg, {skin: 'layui-layer-molv'});
				}else{
					layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				}
			}
		});		
	});
	
	
	//分发更新包
	$('a[name="version_hand_out"]').click(function(){
		var ids = $('input[name="ids"]').val();
		if(ids == ""){
            layer.alert('请先选择要分发更新包的数据！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
        }
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
        var data_url = $('a[name="version_hand_out"]').attr('data-url');
        var g = $("input[name='g']").val();
        var url = data_url+'&g='+g;
        $.ajax({
        	type : 'POST',
    		url : url,
			data : {'ids':ids},
			dataType :'JSON',
			success : function(res){
				layer.close(uploading);
				if(res.status == 1){
					parent.document.getElementById("cz_status").value = 2;
					$("#update_version_info").text('分发更新包操作完成!')
			        layer.alert(res.msg, {skin: 'layui-layer-molv'});
				}else{
					layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				}
			}
		});		
	});
    
    //检查更新包
    $('a[name="version_check"]').click(function(){
		var ids = $('input[name="ids"]').val();
		if(ids == ""){
            layer.alert('请先选择要检查更新包的数据！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
        }
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
        var data_url = $('a[name="version_check"]').attr('data-url');
        var g = $("input[name='g']").val();
        var url = data_url+'&g='+g;
        $.ajax({
        	type : 'POST',
    		url : url,
			data : {'ids':ids},
			dataType :'JSON',
			success : function(res){
				layer.close(uploading);
				if(res.status == 1){
					parent.document.getElementById("cz_status").value = 3;
					$("#update_version_info").text('检查更新包操作完成!')
			        layer.alert(res.msg, {skin: 'layui-layer-molv'});
				}else{
					layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				}
			}
		});		
	});
	
	//更新
    $('a[name="version_update_oper"]').click(function(){
		var ids = $('input[name="ids"]').val();
		if(ids == ""){
            layer.alert('请先选择要更新的数据！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
        }
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
        var data_url = $('a[name="version_update_oper"]').attr('data-url');
        var g = $("input[name='g']").val();
        var url = data_url+'&g='+g;
        $.ajax({
        	type : 'POST',
    		url : url,
			data : {'ids':ids},
			dataType :'JSON',
			success : function(res){
				layer.close(uploading);
				if(res.status == 1){
					parent.document.getElementById("cz_status").value = 4;
					$("#update_version_info").text('更新操作完成!')
			        layer.alert(res.msg, {skin: 'layui-layer-molv'});
				}else{
					layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				}
			}
		});		
	});
	
	//检查版本号
    $('a[name="version_test"]').click(function(){
		var ids = $('input[name="ids"]').val();
		if(ids == ""){
            layer.alert('请先选择要测试的数据！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
        }
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
        var data_url = $('a[name="version_test"]').attr('data-url');
        var g = $("input[name='g']").val();
        var url = data_url+'&g='+g;
        $.ajax({
        	type : 'POST',
    		url : url,
			data : {'ids':ids},
			dataType :'JSON',
			success : function(res){
				layer.close(uploading);
				if(res.status == 1){
					parent.document.getElementById("cz_status").value = 5;
					$("#update_version_info").text('检查版本号操作完成!')
			        layer.alert(res.msg, {skin: 'layui-layer-molv'});
				}else{
					layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				}
			}
		});		
	});
	
	//开服
    $('a[name="version_open_server"]').click(function(){
		var ids = $('input[name="ids"]').val();
		if(ids == ""){
            layer.alert('请先选择要开服的数据！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
        }
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
        var data_url = $('a[name="version_open_server"]').attr('data-url');
        var g = $("input[name='g']").val();
        var url = data_url+'&g='+g;
        $.ajax({
        	type : 'POST',
    		url : url,
			data : {'ids':ids},
			dataType :'JSON',
			success : function(res){
				layer.close(uploading);
				if(res.status == 1){
					parent.document.getElementById("cz_status").value = 6;
					$("#update_version_info").text('开服操作完成!')
			        layer.alert(res.msg, {skin: 'layui-layer-molv'});
				}else{
					layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				}
			}
		});		
	});
	
	
	//操作回到上一步
    $('a[name="version_return"]').click(function(){
    	var cz_status = parent.document.getElementById("cz_status").value;
    	if(cz_status == 0){
    		layer.alert('未进行操作,无需返回上一步操作', {icon: 2, skin: 'layui-layer-molv'});
            return false;
    	}	
    	if(cz_status == 1){
    		layer.alert('不能回到操作1(停服)！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
    	}
    	if(cz_status == 6){
    		layer.alert('操作已经完成,无需返回上一步操作！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
    	}
    	cz_status = cz_status -1;
		var ids = $('input[name="ids"]').val();
		if(ids == ""){
            layer.alert('请先选择要开服的数据！', {icon: 2, skin: 'layui-layer-molv'});
            return false;
        }
		uploading = layer.load(2, {shade: [0.4, '#393D49']});
        var data_url = $('a[name="version_return"]').attr('data-url');
        var g = $("input[name='g']").val();
        var url = data_url+'&g='+g;
        $.ajax({
        	type : 'POST',
    		url : url,
			data : {'ids':ids,'cz_status':cz_status},
			dataType :'JSON',
			success : function(res){
				layer.close(uploading);
				if(res.status == 1){
					parent.document.getElementById("cz_status").value = cz_status;
					$("#update_version_info").text('操作回到上一步完成!')
			        layer.alert(res.msg, {skin: 'layui-layer-molv'});
				}else{
					layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				}
			}
		});		
	});
	
	
    
    
</script>